﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.DAL.Model.Sys;

namespace XQ.RequestOfficeSupplies.DAL.DAL
{
    /// <summary>
    /// 上传表操作类
    /// </summary>
    public class UploadDal:BaseDal<Upload>
    {
        private RequestOfficeSuppliesEntities ce;

        /// <summary>
        /// 保存上传
        /// </summary>
        /// <param name="uploads"></param>
        /// <param name="businessID"></param>
        /// <returns></returns>
        public bool SaveUpload(List<Upload> uploads, int businessID, string tableName, string signName)
        {
            //删除旧的上传关联
            this.DeleteModel(u => u.businessID == businessID && u.signName == signName && u.tableName == tableName);
            if (uploads != null && uploads.Count > 0)
            {
                //保存新的上传
                return this.AddModels(uploads) > 0;
            }
            return false;
        }

        /// <summary>
        /// 获取指定的上传列表
        /// </summary>
        /// <param name="uploads"></param>
        /// <returns></returns>
        public List<Upload> GetUpload(string tableName, string signName, int businessID)
        {
            return this.FindAllModel(u => u.tableName == tableName && u.signName == signName && u.businessID == businessID);
        }

        /// <summary>
        /// 删除指定条件的上传记录
        /// </summary>
        /// <param name="uploads"></param>
        /// <returns></returns>
        public bool DeleteUpload(string tableName, string signName, int businessID)
        {
            return this.DeleteModel(u => u.tableName == tableName && u.signName == signName && u.businessID == businessID) > 0;
        }

        public int SaveAll(List<Upload> uploads)
        {
            //删除旧的关联
            this.DeleteModel(u => u.tableName == uploads[0].tableName && u.signName == uploads[0].signName && u.businessID == uploads[0].businessID);

            //重新增加关联
            return this.AddModels(uploads);
        }
    }
}
